/**
 * Created by China Wang on 5/28/14.
 */
public class Diamond {

    static String name = "China";

    public static void main(String[] args) {
        printIsoscelesTriangle(3);
        System.out.println();
        printDiamond(4);
        System.out.println();
        printDiamondWithName(3);
    }

    // Isosceles Triangle
    // Given a number n, print a centered triangle
    public static void printIsoscelesTriangle(int n) {
        int maxStars = 2*n - 1;
        int starsPerRow = 1;
        for (int i = 0; i < n; i++) {
            printPadding((maxStars-starsPerRow)/2);
            Triangle.printHorizontalLine(starsPerRow);
            starsPerRow += 2;
        }
    }

    private static void printPadding(int n) {
        while (n > 0) {
            System.out.print(" ");
            n--;
        }
    }

    // Diamond
    // Given a number n, print a centered diamond
    public static void printDiamond(int n) {
        printIsoscelesTriangle(n);
        printUpsideDownIsoscelesTriangle(n - 1, " ");
    }

    // Diamond with Name
    // Given a number n, print a centered diamond with your name in place of the middle line
    public static void printDiamondWithName(int n) {
        printIsoscelesTriangle(n - 1);
        System.out.println(name);
        printUpsideDownIsoscelesTriangle(n - 1, "");
    }

    private static void printUpsideDownIsoscelesTriangle(int n, String extraPadding) {
        int maxStars = 2*n - 1;
        int starsPerRow = maxStars;
        while (starsPerRow > 0) {
            printPadding((maxStars-starsPerRow)/2);
            System.out.print(extraPadding);
            Triangle.printHorizontalLine(starsPerRow);
            starsPerRow -= 2;
        }
    }

}
